package erfen;

public class Solution_34 {
    public int[] searchRange(int[] nums, int target) {
        int left = binarySearch(nums, target);
        int right = binarySearch(nums, target + 1)-1;
        if(left>=nums.length||nums[left]!=target)
            return new int[]{-1,-1};
        else if (right>=nums.length||nums[right]!=target)
            return new int[]{left,left};
        return new int[]{left,right};
    }

    public int binarySearch(int[] nums, int target) {
        int left=0,right=nums.length-1;
        while (left<=right){
            int mid=(left+right)>>>1;
            if(nums[mid]>=target)
                right=mid-1;
            else left=mid+1;
        }
        return left;
    }
}
